/**
 * Created by DukeCrushIt on 2015/8/17.
 */
class RemindPanel extends eui.Component{
    public callObj:any=null;
    public okBack:Function=null;
    public cancelBack:Function=null;
    public constructor(){
        super();
        this.skinName = "pet.RemindSkin";
    }
    private img_close:eui.Image;
    private img_pop_bottom_1:eui.Image;
    private img_ok:eui.Image;
    private lab_content:eui.Label;
    public partAdded(name:string, instance:any) {
        super.partAdded(name, instance);
        if (name == "img_close") {
            this.img_close = instance;
            this.img_close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
        } else if (name == "img_pop_bottom_1") {
            this.img_pop_bottom_1 = instance;
        }else  if( name == "img_ok"){
            this.img_ok = instance;
            this.img_ok.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onOk, this);
        }else if( name == "lab_content"){
            this.lab_content = instance;
        }
    }

    private onClose(evt:egret.TouchEvent){
        SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
        if(this.callObj != null && this.cancelBack != null){
            this.cancelBack.call(this.callObj);
        }else if(this.cancelBack != null && this.callObj == null){
            this.cancelBack();
        }
    }

    private onOk(evt:egret.TouchEvent){
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
        if(this.callObj != null && this.okBack != null){
            this.okBack.call(this.callObj);
        }else if(this.okBack != null && this.callObj == null){
            this.okBack();
        }
    }

    public showContent(content:string,callObj:any=null, okFun:Function=null,cancelFun:Function=null,closeShow:boolean=true){
        if( !DisplayController.instance().stage) return;
        DisplayController.instance().addToAlert(GameConst.GrayMask);
        DisplayController.instance().addToAlert(this);
        this.lab_content.text = content;
        this.callObj = callObj;
        this.okBack = okFun;
        this.cancelBack = cancelFun;
        this.img_close.visible = closeShow;
    }

    public measure() {
        super.measure();
        this.x = GameConst.StageW - this.measuredWidth >> 1;
        this.y = GameConst.StageH - this.measuredHeight >> 1;
    }
    private static _instance:RemindPanel;
    public static getInstance():RemindPanel{
        if( RemindPanel._instance == null )
            RemindPanel._instance = new RemindPanel();
        return RemindPanel._instance;
    }
}